package com.cskaoyan.dbutils.handler;

import com.cskaoyan.bean.Account;
import com.cskaoyan.connectionpool.DruidUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.List;

/**
 * 创建日期: 2022/03/24 14:49
 *
 * @author ciggar
 */
public class BeanListHandlerDemo {

    public static void main(String[] args) throws SQLException {

        QueryRunner queryRunner = new QueryRunner(DruidUtils.getDataSource());

        List<Account> list = queryRunner.query("select * from account",new BeanListHandler<>(Account.class));

        System.out.println(list);

        Account account = list.get(0);

        Integer id = account.getId();

        System.out.println("id:" + id);

    }

}
